<?session_start();
	//session_register('kart_array');
	?>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
	<link rel="stylesheet" type="text/css" href="css/cart.css" />

	<script language="javascript">
	function change_times2(t2){
		switch(t2){
				case '1':
					document.frm_kart.times2.value = '1' ;
					break;
				case '2':
					document.frm_kart.times2.value = '2' ;
					break;
				case '3':
					document.frm_kart.times2.value = '3' ;
					break;
				default:
					break;
			}
	}
	</script>

	<script language="javascript">
	$().ready(function(){
		$("#buy_one").click();			   
	})

	////定義使用者點擊"付款方式"radio按鈕時，觸發的功能。
	function change_value(s,m){
			switch(s){
				case '1_1':
					document.frm_kart.action = 'kart_checkout.php' ;
					document.frm_kart.client.value = '1_1' ;
					document.frm_kart.amount.value = m ;
					document.frm_kart.stage.value = '1' ;
					break;
				case '1_2':
					document.frm_kart.action = 'kart_checkout.php' ;
					document.frm_kart.client.value = '1_2' ;
					document.frm_kart.amount.value = m ;
					document.frm_kart.stage.value = '1' ;
					break;
				case '1_3':
					document.frm_kart.action = 'kart_checkout.php' ;
					document.frm_kart.client.value = '1_3' ;
					document.frm_kart.amount.value = m ;
					document.frm_kart.stage.value = '1' ;
					break;
				case '1_4':
					document.frm_kart.action = 'kart_checkout.php' ;
					document.frm_kart.client.value = '1_4' ;
					document.frm_kart.amount.value = m ;
					document.frm_kart.stage.value = '1' ;
					break;
				case '3':
					document.frm_kart.action = 'https://ecpay.com.tw/form_Sc_to5.php' ;
					document.frm_kart.client.value = '3' ;
					document.frm_kart.amount.value = m ;
					document.frm_kart.stage.value = '1' ;
					break;
				case '4_1':
					document.frm_kart.action = 'https://ecpay.com.tw/form_Sc_to5_fn.php' ;
					document.frm_kart.client.value = '4' ;
					document.frm_kart.amount.value = m ;
					document.frm_kart.stage.value = '3' ;
					break;
				case '4_2':
					document.frm_kart.action = 'https://ecpay.com.tw/form_Sc_to5_fn.php' ;
					document.frm_kart.client.value = '4' ;
					document.frm_kart.amount.value = m ;
					document.frm_kart.stage.value = '6' ;
					break;
				case '4_3':
					document.frm_kart.action = 'https://ecpay.com.tw/form_Sc_to5_fn.php' ;
					document.frm_kart.client.value = '4' ;
					document.frm_kart.amount.value = m ;
					document.frm_kart.stage.value = '12' ;
					break;
				case '4_4':
					document.frm_kart.action = 'https://ecpay.com.tw/form_Sc_to5_fn.php' ;
					document.frm_kart.client.value = '4' ;
					document.frm_kart.amount.value = m ;
					document.frm_kart.stage.value = '24' ;
					break;
				default:
					break;
			}
	}



	    function form_submit(){
		
			  <!--訂購人電子郵件未填寫-->
			    var d_date = $('#shoppermail').val();
				if(d_date == ''){
					alert('訂購人電子郵件未填寫');
					$('#shoppermail').focus();
					return false;
					}
				
				
			if(!$('#sameasorder').attr('checked')){
				<!--收貨人人電子郵件未填-->
			    var d_date = $('#consigneemail').val();
				if(d_date == ''){
					alert('收貨人人電子郵件未填');
					$('#consigneemail').focus();
					return false;
					}
				
			}
		
				
			  
				
			   <!--到貨日期未填寫-->
				var d_date = $('#d_date').val();
				if(d_date == ''){
					alert('到貨日期未填寫');
					$('#d_date').focus();
					return false;
				}
		
				<!--判斷早.中.晚的值始-->		
				if($('#times2').val() == '1'){
					$('#names').val( $('#names').val() + '[早(9:00-12:00)' + $('#d_date').val() + ']' );
				}
				else if($('#times2').val() == '2'){
					$('#names').val( $('#names').val() + '[中(12:00-17:00)'  + $('#d_date').val() + ']' );
				}
				else if($('#times2').val() == '3'){
					$('#names').val( $('#names').val() + '[晚(17:00-21:00)'  + $('#d_date').val() + ']' );
				}
				<!--判斷早.中.晚的值結束-->	
			$.post('order_save.php', $('#frm_kart').serialize().replace('\'','\\\''), function(data){

					if(data == 0){
						alert("訂單資料未填寫") ;
					}else{
					document.frm_kart.od_sob.value = data ;
					document.frm_kart.submit();
				}
	       });

		}



	</script>
	<?
	//$_SESSION['kart_array'] = $_SESSION['kart_array'] ;
	$path = '../Mkart/';
	$ord_path = 'http://www.ricepool.com';
	include($path."common.php");
	include($path."prod_fun.php");
	//引用外部用來計算專屬於小烏龜專案的運費的PHP檔案。
	include($path . 'calculate_fare_for_tortoise.php');
	?>
	<table width=100% border=0 align="center" cellpadding="4" cellspacing="0" class="maycart_page_top_bg">
	<td align="center"  class="maycart_page_top">
	</td>
	</table>
	<table width=730px border="0" align="center" cellpadding="0" cellspacing="0" class="top_btn">
	  <tr>
	    <td width=10px></td>
	    <td class="btn_circle"><a href="../index.php?option=com_content&view=frontpage&Itemid=60">首頁</a></td>
	    <td class="btn_circle"><a href="../index.php?option=com_content&amp;view=section&amp;layout=blog&amp;id=6&amp;Itemid=54">最新消息</a></td>
	    <td class="btn_circle"><a href="../index.php?option=com_content&amp;view=section&amp;layout=blog&amp;id=7&amp;Itemid=55">關於我們</a></td>
	    <td class="btn_circle"><a href="../index.php?option=com_content&amp;view=section&amp;layout=blog&amp;id=8&amp;Itemid=56">產品介紹</a></td>
	    <td class="btn_circle"><a href="../index.php?option=com_phocaguestbook&amp;view=phocaguestbook&amp;id=1&amp;Itemid=64">聯絡我們</a></td>
	    <td class="btn_circle"><a href="../index.php?option=com_content&amp;view=section&amp;layout=blog&amp;id=10&amp;Itemid=58">購物需知</a></td>
	     <td width=30px></td>
	    
	    <td align="center"><a href="http://www.facebook.com/yihongc?sk=photos" target="_blank"><img src="images/facebook_btn.png" width="24" height="24" border="0" /></a></td>
	    
	    <td><a href="../index.php?option=com_content&amp;view=section&amp;layout=blog&amp;id=10&amp;Itemid=65" target="_blank"><img src="images/shoppingcart_btn.png" width="95" height="26" border="0" /></a></td>
	  </tr>
	</table>





	<table width=723px border=0 align="center" cellpadding="4" cellspacing="0">
	<td class="mycart_title"></td>
	</table>

	<table width=723px border=0 align="center" cellpadding="4" cellspacing="0">
	<td class="shopping_process1"></td>
	</table>


	<table width=723px border=0 align="center" cellpadding="4" cellspacing="0">
	<td class="shopping_padding"></td>
	</table>






	<table width=723px border=0 align="center" cellpadding="4" cellspacing="0">
	<td align=center>商品名稱</td>
	<td align=center width=10%>單價</td>
	<td align=center width=10%>數量</td>
	<td align=center width=10%>小計</td>

	</tr>
	<tr><td colspan=5><hr noshade style="border:2px solid #9FC937;"></tr>
	<?php
	for($i=0;$i<count($_SESSION['kart_array']);$i++)
	{

		//該商品的ID。	
		$prodid = $_SESSION['kart_array'][$i]["id"] ;
		//該商品的名稱。
		$prodname = $_SESSION['kart_array'][$i]["name"] ;
		//該商品的購買數量。
		$prodcount = $_SESSION['kart_array'][$i]["count"] ;
		//該商品的總消費金額 = 該商品單價 * 該商品的購買數量。
		$prodprice = $_SESSION['kart_array'][$i]["price"] ;


		//＠組合要送到後面頁面(?)的資料，分別是：
		//@CSV格式的被購買的所有商品ID($prod_list)。
		//@CSV格式的被購買的所有商品數量($prod_list_sum)。
		if($i == count($_SESSION['kart_array'])-1){
		$prod_list .= $prodid ;
		}else{
		$prod_list .= $prodid.",";
		}
		if($i == count($_SESSION['kart_array'])-1){
		$prod_list_sum .= $prodcount ;
		}else{
		$prod_list_sum .= $prodcount.",";
		}

		//@這裡的碼半途而廢，只寫了一半，沒有發揮任何作用。
		$sql = "select * from product where id = '$prodid' order by id" ;
		$result = mysql_query($sql) ;
		$row = mysql_fetch_object($result) ;
		$qty = $row -> pd_count ;
		//...廢碼的結尾。
	?>


		<tr>
		<!--在購買清單裡顯示商品名稱-->
		<td align="center" ><?php echo $prodname?></td>
		<!--在購買清單裡顯示商品單價-->
		<td align=center ><?php echo $prodprice / $prodcount ?></td>
		<!--在購買清單裡顯示商品數量-->
		<td align=center ><?php echo  $prodcount ?></td>
		<!--在購買清單裡顯示小計價格-->
		<td align=center class="red" >NT$<?php echo $prodprice?></td>
		</tr>

		<tr>
		<!--在購買清單裡顯示一條分隔線，用來分隔購買清單裡不同的商品-->
		<td colspan=5><hr style="border:2px solid #9FC937;">
		</tr>

	<?php }?>

	</table>

	<?php
	//計算並取得消費總金額。 
	$price_sum  = count_array('price',$_SESSION['kart_array']) ;

	$sql_rate = "select * from stage " ;
	$result_rate = mysql_query($sql_rate);
	$row_rate=mysql_fetch_object($result_rate) ;
	$rate_1 = $row_rate->three_rate ;
	$rate_2 = $row_rate->six_rate ;
	$rate_3 = $row_rate->twelve_rate ;
	$rate_4 = $row_rate->tf_rate ;
	//取得免運費的資格，例如：4500元以上免運費。
	$fare_limit = $row_rate->fare_limit;
	$fare = $row_rate->fare ;

	//@如果消費總金額達到免運費資格，消費總金額就不再加上運費。
	if($price_sum >= $fare_limit)
	{
		$price_sum = $price_sum;
		$buff_text = '運費 0 元' ;
	}
	//@如果未達到免運費資格，消費總金額就要再加上運費。
	elseif($price_sum < $fare_limit)
	{
		//從外部專門計算小烏龜專案運費的檔案(../Mkart/calculate_fare_for_tortoise.php)裡取得運費。
		$fare = $fare_at_calculate_fare_for_tortoise_php_file;
		$price_sum += $fare;
		$buff_text = '運費 ' . $fare . ' 元' ;
	}


	$pric_rate3 = floor($price_sum * (($rate_1+100)/100)) ;
	$pric_rate6 = floor($price_sum * (($rate_2+100)/100)) ;
	$pric_rate12 = floor($price_sum * (($rate_3+100)/100)) ;
	$pric_rate24 = floor($price_sum * (($rate_4+100)/100)) ;
	?>
	
<table width="723" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="right" ><?php echo $buff_text;?></td>
</tr>
<tr>
<td height="10" align="right" ></td>
</tr>
<tr>
<td align="right">總金額:<span class="red">NT$<?php echo $price_sum?></span>元</td>
</tr>
</table>

	<form method=post id="frm_kart" name="frm_kart" action=''>
	<table width=723px border=0 align=center cellpadding="6" cellspacing="0" >
	<input name=item_list type=hidden size=500 value='<?php echo $prod_list?>'>
	<input name=item_list_sum type=hidden size=500 value='<?php echo $prod_list_sum?>'>
	<input name=shop_amount type=hidden size=500 value='<?php echo $price_sum?>'>
	<input type=hidden name=roturl value='<?php echo $ord_path?>Mkart/order_roturl.php'>
	<input type=hidden name=bk_posturl value='<?php echo $ord_path?>Mkart/order_bk.php'>

	<input type=hidden name=act value='auth'>
	<input type=hidden name=client value=''>
	<input type=hidden name=stage value=''>
	<input type=hidden name=amount value=''>
	<input type=hidden name=od_sob value=''>
	<!--早中晚的初始值-->
	<input type=hidden id=times2 name=times2 value=''>

	<tr>
	<td>

	<table width=99% border=0 align=center cellpadding="6" cellspacing="0"  class=pay_info>
	<tr><td colspan=2 class=darkblue>訂購人</td></tr>
	<tr>
	  <td align=left width=20%>姓名:</td>
	  <td align=left><input id=names name=shopper_name type=text size=20 value=''><font color=red>*</font></td>
	</tr>

	<tr>
	<td align=left >市話:</td>
	<td align=left >  <input name=shopper_tel type=text size=12 value=''></td>
	</tr>

	<tr>
	<td align=left>手機:</td>
	<td align=left><input name=shopper_phone type=text size=12 value=''><font color=red>*</font></td>
	</tr>

	<tr>
	<td align=left>電子郵件:</td>
	<td align=left ><input id='shoppermail' name=shopper_mail type=text size=30 value=''><font color=red>*</font></td>
	</tr>

	<tr>
	<td align=left>郵遞區號:</td>
	<td align=left><input name=shopper_zip type=text size=5 value=''></td>
	</tr>

	<tr>
	<td align=left >地址:</td>
	<td align=left ><input name=shopper_address type=text size=30 value=''><font color=red>*</font></td>
	</tr>

	<tr>
	<td height="38" >&nbsp;</td>
	<td >&nbsp;</td>
	</tr>
	<tr>
	<td >&nbsp;</td>
	<td >&nbsp;</td>
	</tr>
	</table>
	</td>


	<td>
	<table width=100% border=0 align=center cellpadding="6" cellspacing="0" class=pay_info>
	<tr><td colspan=2 class="darkblue">收貨人<input id="sameasorder" type=checkbox name=consigenee_check value='Y'>同訂購人</td></tr>
	<tr>
	  <td align=left width=20%>姓名:</td>
	  <td align=left><input name=consignee_name type=text size=20 value=''><font color=red>*</font></td>
	</tr>

	<tr>
	<td align=left  >市話:</td>
	<td align=left ><input name=consignee_tel type=text size=12 value=''></td>
	</tr>

	<tr>
	<td align=left>手機:</td>
	<td align=left><input name=consignee_phone type=text size=12 value=''><font color=red>*</font></td>
	</tr>

	<tr>
	<td align=left >電子郵件:</td>
	<td align=left><input id='consigneemail'name=consignee_mail type=text size=30 value=''><font color=red>*</font></td>
	</tr>

	<tr>
	<td align=left>郵遞區號:</td>
	<td align=left><input name=consignee_zip type=text size=5 value=''></td>
	</tr>

	<tr>
	<td align=left>地址:</td>
	<td align=left ><input name=consignee_address type=text size=30 value=''><font color=red>*</font></td>
	</tr>


	<!--選擇早.中.晚-->
	<tr>
	<td align=left>到貨時間:</td>
	<td align=left>
	<input name=time2 type=radio value='1' onclick="change_times2('1')">早(9-12) 
	<input name=time2 type=radio value='2' onclick="change_times2('2')">中(12-17) 
	<input name=time2 type=radio value='3' onclick="change_times2('3')">晚(17-21) 
	</td>
	</tr>

	<tr>
	<td align=left>到貨日期:</td>
	<td align=left ><input id='d_date' name=getdate type=text size=30 value=''><font color=red>*(年/月/日)</font></td>
	</tr>

	</table>
	</td>
	</tr>

	<tr>
	  <td colspan=2>
	<table width=99% border=0 align=center cellpadding="6" cellspacing="0">
	<tr>
	<td width=12% align="left" class=font>發票抬頭:</td>
	<td width="92%" align=left><input name=invoice type=text size=20 value=''></td>
	</tr>

	<tr>
	<td align="left" class=font>統一編號:</td>
	<td align=left><input name=invoice_no type=text size=20 value=''></td>
	</tr>



	</table>
	</td></tr>

	<tr>
	  <td colspan=2>
	  
	<table width=723px border=0 align="center" cellpadding="4" cellspacing="0">

	<tr>
	<td ><hr style="border:2px solid #9FC937;"></td>
	<td class="green_line_none"></td>
	<td ><hr style="border:2px solid #9FC937;"></td>
	</tr>
	</table>




	<table width=723px border=0 align="center" cellpadding="4" cellspacing="0">
	<td class="shopping_process3"></td>
	</table>


	<table width=723px border=0 align="center" cellpadding="4" cellspacing="0">
	<td ><hr style="border:2px solid #9FC937;"></td>
	<td class="green_line_none"></td>
	<td ><hr style="border:2px solid #9FC937;"></td>
	</table>










	<table width=100% border=1 align=center cellpadding="0" cellspacing="0" class=pay>


	<tr>

	<!--
	<td colspan=4 align=center class="blue">
	分期付款(<font color=red>除不盡餘數於第一期收取</font>)
	</td>
	-->
	</tr>

	<tr>

	<td align=left>
	<input name=type type=radio value='1_1' onclick="change_value('1_1',<?echo $price_sum?>)">
	<p>ATM轉帳</p>
	<p> 匯款帳號:土地銀行(代號005)青年分行 <br />
	  戶名:吳瑞美 <br />
	  帳號:038005224915<br />
	  若是選擇銀行匯款之客戶,<br />
	  請將匯款完成後的單據回傳至本公司,<br />
	  待確認款項後,即為您安排出貨事宜。 
	</p>

	</td>

	<!--
	<td align=center>
	<input name=type type=radio value='1_2' onclick="change_value('1_2',<?echo $price_sum?>)">銀行匯款
	</td>
	<td align=center>
	<input name=type type=radio value='1_3' onclick="change_value('1_3',<?echo $price_sum?>)">WebAtm
	</td>  
	-->



	<td align=left >

	<input name=type type=radio value='1_4' onclick="change_value('1_1',<?echo $price_sum?>)">
	<p>貨到付款</p>
	<p>由宅配人員代收貨款<br />
	  貨到付款,不另加手續費<br />
	  請註明低溫宅急便。</p>

	</td>

	<!--
	<td align=center>
	<input name=type type=radio value='3' onclick="change_value('3',<?echo $price_sum?>)">一次刷卡
	</td>

	<td align=center>
	<input name=type type=radio value='4_1' onclick="change_value('4_1',<?php echo $pric_rate3?>)">3期<?php echo $rate_1?>%利率
	</td>
	<td align=center>
	<input name=type type=radio value='4_2' onclick="change_value('4_2',<?php echo $pric_rate6?>)">6期<?php echo $rate_2?>%利率
	</td>
	<td align=center>
	<input name=type type=radio value='4_3' onclick="change_value('4_3',<?php echo $pric_rate12?>)">12期<?php echo $rate_3?>%利率
	</td>
	<td align=center>
	<input name=type type=radio value='4_4' onclick="change_value('4_4',<?php echo $pric_rate24?>)">24期<?php echo $rate_4?>%利率
	</td>
	-->




	</tr>



	<tr>

	<td align=center>
	<hr style="border:2px solid #9FC937; margin-right:87px;">
	<?php echo $price_sum?>元
	<hr style="border:2px solid #9FC937; margin-right:87px;">
	</td>
	<!--
	<td align=center>
	<?php echo $price_sum?>元
	</td>
	<td align=center>
	<?php echo $price_sum?>元
	</td> 
	 -->

	<td align=center>
	<hr style="border:2px solid #9FC937; margin-right:0px;">
	<?php echo $price_sum?>元
	<hr style="border:2px solid #9FC937; margin-right:0px;">
	</td>
	<!--
	<td align=center>
	<?php echo $price_sum?>元
	</td>

	<td align=center>
	<?php echo floor($pric_rate3/3)?>元
	<br>
	X
	<br>
	3期
	<br>
	總計:<?php echo $pric_rate3?>元
	</td>
	<td align=center>
	<?php echo floor($pric_rate6/6)?>元
	<br>
	X
	<br>
	6期
	<br>
	總計:<?php echo $pric_rate6?>元
	</td>
	<td align=center>
	<?php echo floor($pric_rate12/12)?>元
	<br>
	X
	<br>
	12期
	<br>
	總計:<?php echo $pric_rate12?>元
	</td>
	<td align=center>
	<?php echo floor($pric_rate24/24)?>元
	<br>
	X
	<br>
	24期
	<br>
	總計:<?php echo $pric_rate24?>元
	</td>
	-->
	</tr>
	</table>










	</td></tr>

	<tr>
	<td align=center colspan=2>
	<input id=buy class="sumbit" name=buy type=button value='開始結帳' onclick="if(!confirm('確定開始結帳？')){return false;};form_submit();">
	</td>
	</tr>

	</table>
	</form>



	<table width=100% border=0 align="center" cellpadding="4" cellspacing="0" class="maycart_page_down_bg">
	<a href="http://www.finpo.com.tw"><td class="maycart_page_down"></td></a>
	</table>

